/*****************************************************************************
*        描述 :
*             文件描述
*        CLR版本:            3.5
*        创建者 :            蒋 光
*        个人域名:           jiangguang.net.cn
*        命名空间名称:       ECP.Service
*        文件名:             ExceptionService.svc.cs
*        创建系统时间:       2012/11/2 19:07:04
*        创建年份:           2012
*
/*****************************************************************************/

namespace ECP.Service
{
    using System;
    using System.Data;
    using System.Reflection;
    using System.ServiceModel;
    using ECP.DataAccess;
    using ECP.DataAccess.Utilities;
    using ECP.Interface;
    using ECP.Model;
    using ECP.Utilities;

    [ServiceBehavior(Namespace = "http://jiangguang.net.cn/")]
    public partial class ExceptionService : MarshalByRefObject, IExceptionService
    {
        private static ExceptionService instance = null;
        private static object locker = new object();

        public DataTable BatchDelete(BaseUserInfo userInfo, string[] ids)
        {
            DataTable dT = new DataTable(BaseExceptionTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseExceptionDao dao = new BaseExceptionDao(dbHelper, userInfo);
                dao.BatchDelete(BaseExceptionTable.FieldID, ids);
                dT = dao.GetDT();
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return dT;
        }

        public DataTable Delete(BaseUserInfo userInfo, string id)
        {
            DataTable dT = new DataTable(BaseExceptionTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseExceptionDao dao = new BaseExceptionDao(dbHelper, userInfo);
                dao.Delete(id);
                dT = dao.GetDT();
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return dT;
        }

        public DataTable GetList(BaseUserInfo userInfo)
        {
            DataTable dT = new DataTable(BaseExceptionTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                dT = new BaseExceptionDao(dbHelper, userInfo).GetDT();
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return dT;
        }

        public void Load()
        {
        }

        public DataTable Truncate(BaseUserInfo userInfo)
        {
            DataTable dT = new DataTable(BaseExceptionTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseExceptionDao dao = new BaseExceptionDao(dbHelper, userInfo);
                dao.Truncate();
                dT = dao.GetDT();
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return dT;
        }

        public static ExceptionService Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (locker)
                    {
                        if (instance == null)
                        {
                            instance = new ExceptionService();
                        }
                    }
                }
                return instance;
            }
        }
    }
}